var t = getApp(), e = t.requirejs("core"), o = t.requirejs("foxui");

Page({
    data: {
        icons: t.requirejs("icons"),
        success: !1,
        successData: {},
        coupon: !1,
        paypwd:''
    },
    onLoad: function(e1) {



        this.setData({
            options: e1,
            imgUrl: t.globalData.approot
        }), t.url(e);
    },
    onShow: function() {
        var that=this;
         /*微信 登录*/
        wx.login({
            success (res) {
                console.log(res);
                if (res.code) {
                    e.post("wxapp/login", {
                          code: res.code
                      }, function(t1) {
                        console.log('t1',t1);
                        var options=that.data.options;
                        if(t1.openid){

                            options.re_openid=t1.openid;
                            that.setData({
                                options:options,
                            })
                            that.get_list();
                        }
                    });
                } else {
                  console.log('登录失败！' + res.errMsg)
                }
            }
        })



    },
    get_list: function() {
        var t = this;

        console.log(t.data.options);
        e.get("order/pay", t.data.options, function(o) {
          //50018 != o.error ? (!o.wechat.success && "0.00" != o.order.price && o.wechat.payinfo && e.alert(o.wechat.payinfo.message + "\n不能使用微信支付!"),
            50018 != o.error ? (!o.wechat.success && "0.00" != o.order.price && o.wechat.payinfo ,
            t.setData({
                list: o,
                show: !0
            })) : wx.navigateTo({
                url: "/pages/order/details/index?id=" + t.data.options.id
            });
        });

    },
    listChange: function(t) {
        var e = this.data;
        switch (t.target.id) {
          case "paypwd":
            e.paypwd = t.detail.value;
            break;

          case "realname":
            e.member.realname = t.detail.value;
            break;

          case "mobile":
            e.member.mobile = t.detail.value;
        }
        this.setData({
            paypwd: e.paypwd
        });
    },
    pay: function(t) {
        var a = e.pdata(t).type, s = this, i = this.data.list.wechat;
        e.post("order/pay/checkstock", {
            id: s.data.options.id
        }, function(t) {
            0 == t.error ? "wechat" == a ? e.pay(i.payinfo, function(t) {
                "requestPayment:ok" == t.errMsg && s.complete(a);
            }) : "credit" == a ? e.confirm("确认要支付吗?", function() {
                s.complete(a);
            }, function() {}) : "cash" == a ? e.confirm("确认要使用货到付款吗?", function() {
                s.complete(a);
            }, function() {}) : s.complete(a) : o.toast(s, t.message);
        }, !0, !0);
    },
    complete: function(t) {
        var a = this;
        e.post("order/pay/complete", {
            id: a.data.options.id,
            type: t,
            paypwd:a.data.paypwd
        }, function(t) {
            if (0 != t.error) o.toast(a, t.message); else {
                wx.setNavigationBarTitle({
                    title: "支付成功"
                });
                var e = Array.isArray(t.ordervirtual);
                a.setData({
                    success: !0,
                    successData: t,
                    order: t.order,
                    ordervirtual: t.ordervirtual,
                    ordervirtualtype: e
                });
            }
        }, !0, !0);
    },
    shop: function(t) {
        0 == e.pdata(t).id ? this.setData({
            shop: 1
        }) : this.setData({
            shop: 0
        });
    },
    phone: function(t) {
        e.phone(t);
    },
    closecoupon: function() {
        this.setData({
            coupon: !1
        });
    }
});